﻿using LxCore;

namespace LxCore
{
    public class MaterialProperty : JsObject
    {
        public string Name
        {
            get => _Name;
            set { _Name = value; RaisePropertyChanged(nameof(Name)); }
        }
        private string _Name = "初始值";
        public FieldBase<double> Density
        {
            get => _Density;
            set { _Density = value; RaisePropertyChanged(nameof(Density)); }
        }
        private FieldBase<double> _Density = ConstField.Double1;
        public FieldBase<double> SpecificHeat
        {
            get => _SpecificHeat;
            set { _SpecificHeat = value; RaisePropertyChanged(nameof(SpecificHeat)); }
        }
        private FieldBase<double> _SpecificHeat = ConstField.Double1;
        public AnisotropyTypes ThermalAnisotropyType
        {
            get => _ThermalAnisotropyType;
            set { _ThermalAnisotropyType = value; RaisePropertyChanged(nameof(ThermalAnisotropyType)); }
        }
        private AnisotropyTypes _ThermalAnisotropyType = AnisotropyTypes.各向同性;

        public FieldBase<double> ThermalConductivity
        {
            get => _ThermalConductivity;
            set { _ThermalConductivity = value; RaisePropertyChanged(nameof(ThermalConductivity)); }
        }
        private FieldBase<double> _ThermalConductivity = ConstField.Double1;
        public FieldBase<double> k11
        {
            get => _k11;
            set { _k11 = value; RaisePropertyChanged(nameof(k11)); }
        }
        public FieldBase<double> k12
        {
            get => _k12;
            set { _k12 = value; RaisePropertyChanged(nameof(k12)); }
        }
        public FieldBase<double> k13
        {
            get => _k13;
            set { _k13 = value; RaisePropertyChanged(nameof(k13)); }
        }
        public FieldBase<double> k21
        {
            get => _k21;
            set { _k21 = value; RaisePropertyChanged(nameof(k21)); }
        }
        public FieldBase<double> k22
        {
            get => _k22;
            set { _k22 = value; RaisePropertyChanged(nameof(k22)); }
        }
        public FieldBase<double> k23
        {
            get => _k23;
            set { _k23 = value; RaisePropertyChanged(nameof(k23)); }
        }
        public FieldBase<double> k31
        {
            get => _k31;
            set { _k31 = value; RaisePropertyChanged(nameof(k31)); }
        }
        public FieldBase<double> k32
        {
            get => _k32;
            set { _k32 = value; RaisePropertyChanged(nameof(k32)); }
        }
        public FieldBase<double> k33
        {
            get => _k33;
            set { _k33 = value; RaisePropertyChanged(nameof(k33)); }
        }
        private FieldBase<double> _k11 = ConstField.Double1;
        private FieldBase<double> _k12 = ConstField.Double1;
        private FieldBase<double> _k13 = ConstField.Double1;
        private FieldBase<double> _k21 = ConstField.Double1;
        private FieldBase<double> _k22 = ConstField.Double1;
        private FieldBase<double> _k23 = ConstField.Double1;
        private FieldBase<double> _k31 = ConstField.Double1;
        private FieldBase<double> _k32 = ConstField.Double1;
        private FieldBase<double> _k33 = ConstField.Double1;
        public FieldBase<double> Viscosity
        {
            get => _Viscosity;
            set { _Viscosity = value; RaisePropertyChanged(nameof(Viscosity)); }
        }
        private FieldBase<double> _Viscosity = ConstField.Double1;
        public FieldBase<double> ThermalExpansionCoefficent
        {
            get => _ThermalExpansionCoefficent;
            set { _ThermalExpansionCoefficent = value; RaisePropertyChanged(nameof(ThermalExpansionCoefficent)); }
        }
        private FieldBase<double> _ThermalExpansionCoefficent = ConstField.Double0;

        public override void FromJsonKV(string key, IJsonReader jsReader)
        {
            switch (key)
            {
                case nameof(Name): Name = jsReader.ReadString(); break;
                case nameof(Density): jsReader.ReadObject(Density, e => Density = e); break;
                case nameof(SpecificHeat): jsReader.ReadObject(SpecificHeat, e => SpecificHeat = e); break;
                case nameof(ThermalConductivity): jsReader.ReadObject(ThermalConductivity, e => ThermalConductivity = e); break;
                case nameof(Viscosity): jsReader.ReadObject(Viscosity, e => Viscosity = e); break;
                default: base.FromJsonKV(key, jsReader); break;
            }
        }
        public override void ToJsonKV(IJsonWriter jsWriter)
        {
            base.ToJsonKV(jsWriter);
            PhysicalModel pm = Parent as PhysicalModel;
            jsWriter.WriteString(nameof(Name), Name);
            jsWriter.WriteObject(nameof(Density), Density, true);
            if (pm.IsEnergyEnabled)
            {
                jsWriter.WriteObject(nameof(SpecificHeat), SpecificHeat, true);
                jsWriter.WriteObject(nameof(ThermalConductivity), ThermalConductivity, true);
            }
            if(pm.FlowType!=null)
            {
                jsWriter.WriteObject(nameof(Viscosity), Viscosity, true);
            }
        }
    }
}
